import axios from "../../http/axios.js";
import {
  apiOrderPay
} from "../../http/server.js"

/**
 * @params: option 
 * {
 *  orderNum: 1234566,订单号
 *  orderMoney: 12 订单价格
 * }
 */
export function pay(option) {
  return new Promise((resolve, reject) => {
    axios({
      url: apiOrderPay,
      method: "POST",
      data: {
        openid: wx.getStorageSync('userInfo').openid,
        orderNo: option.orderNo
      }
    }).then(res => {
      wx.requestPayment({
        timeStamp: String(res.timeStamp),
        nonceStr: res.nonceStr,
        package: res.prepayId,
        signType: res.signType,
        paySign: res.paySign,
        success(res) { // 用户手动付款成功
          resolve(res);
        },
        fail(err) { // 用户手动点击x付款失败
          reject(err);
        }
      })
    })
  })
}